package com.example.mall.web.controller;

import com.example.mall.domain.LogisticsOrders;
import com.example.mall.dto.LogisticsOrdersDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.LogisticsOrdersQuery;
import com.example.mall.query.PageDTO;
import com.example.mall.result.JSONResult;
import com.example.mall.service.ILogisticsOrdersService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/logisticsOrders")
public class LogisticsOrdersController {

    @Autowired
    public ILogisticsOrdersService logisticsOrdersService;

    /**
     * 分页查询物流单表信息
     * @param logisticsOrdersQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询物流单表信息",notes = "分页查询物流单表信息",httpMethod = "GET")
    public JSONResult queryPage(LogisticsOrdersQuery logisticsOrdersQuery){
        PageDTO<LogisticsOrdersDto> logisticsOrdersDtoPageDTO = logisticsOrdersService.queryPage(logisticsOrdersQuery);
        return JSONResult.success("查询成功",logisticsOrdersDtoPageDTO);
    }

    /**
     * 根据id查询物流单表信息
     * @param logisticsId
     * @return
     */
    @GetMapping("query/{logisticsId}")
    @ApiOperation(value = "根据id查询物流单表信息",notes = "根据id查询物流单表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("logisticsId")Long logisticsId){
        //1.根据id查询用户信息
        if (logisticsId == null){
            throw new GlobalCustomerException(ErrorEnumCode.LOGISTICSID_NOT_ID);
        }
        LogisticsOrders logisticsOrders = logisticsOrdersService.getById(logisticsId);
        return JSONResult.success("查询成功",logisticsOrders);
    }

    /**
     * 根据id查询物流单表信息
     * @param logisticsId
     * @return
     */
    @GetMapping("queryLogisticsOrdersById/{logisticsId}")
    @ApiOperation(value = "根据id查询物流单表信息",notes = "根据id查询物流单表信息",httpMethod = "GET")
    public JSONResult queryLogisticsOrdersById(@PathVariable("logisticsId")Long logisticsId){
        //1.根据id查询用户信息
        if (logisticsId == null){
            throw new GlobalCustomerException(ErrorEnumCode.LOGISTICSID_NOT_ID);
        }
        LogisticsOrders logisticsOrders = logisticsOrdersService.queryLogisticsOrdersById(logisticsId);
        return JSONResult.success("查询成功",logisticsOrders);
    }

    /**
     * 查询全部物流单表信息
     * @param
     * @return
     */
    @GetMapping("queryLogisticsOrdersList")
    @ApiOperation(value = "查询全部物流单表信息",notes = "查询全部物流单表信息",httpMethod = "GET")
    public JSONResult queryLogisticsOrdersList(){
        List<LogisticsOrders> logisticsOrders = logisticsOrdersService.queryLogisticsOrdersList();
        return JSONResult.success("查询成功",logisticsOrders);
    }

    /**
     * 新增物流单表
     * @param logisticsOrdersDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增物流单表",notes = "新增物流单表",httpMethod = "POST")
    public JSONResult insert(@RequestBody LogisticsOrdersDto logisticsOrdersDto){
        logisticsOrdersService.insert(logisticsOrdersDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改物流单表信息
     * @param logisticsOrdersDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改物流单表信息",notes = "修改物流单表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody LogisticsOrdersDto logisticsOrdersDto){
        logisticsOrdersService.update(logisticsOrdersDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除物流单表信息
     * @param logisticsId
     * @return
     */
    @PostMapping("delete/{logisticsId}")
    @ApiOperation(value = "删除物流单表信息",notes = "删除物流单表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("logisticsId") Long logisticsId) {
        logisticsOrdersService.delete(logisticsId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除物流单表信息
     * @param logisticsIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除物流单表信息",notes = "批量删除物流单表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> logisticsIds) {
        logisticsOrdersService.deleteBatch(logisticsIds);
        return JSONResult.success("批量删除成功");
    }
}
